package linker.window;
 
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

public class AdvencedAccountSetting extends JFrame implements ActionListener {
	// @_@
	private static final long serialVersionUID = 1L;

	private static AdvencedAccountSetting setting = null;

	private JTextField hostField = new JTextField(15);

	private JTextField portField = new JTextField(5);

	private JTextField domainField = new JTextField(15);

	private JButton saveButton = new JButton("Save");

	private static LoginWindow savelw;

	private AdvencedAccountSetting() {
		super("AdvencedAccountSetting");
		setName("Setting");

		Container container = getContentPane();
		container.setLayout(new FlowLayout());

		container.add(new JLabel("Host:"));
		container.add(hostField);
		container.add(new JLabel("Port:"));
		container.add(portField);
		container.add(new JLabel("Domain:"));
		container.add(domainField);
		saveButton.addActionListener(this);
		container.add(saveButton);

		setSize(400, 400);
		setLocationRelativeTo(null);
	}

	public static AdvencedAccountSetting setLoginWindow(LoginWindow lw) {
		if (setting == null)
			setting = new AdvencedAccountSetting();

		setting.setVisible(true);
		
		savelw = lw; 
		
		return setting;
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == saveButton) {
			String host = hostField.getText();
			if (host.length() < 1)
				host = null;

			String port = portField.getText();
			if (port.length() < 1)
				port = null;

			String domain = domainField.getText();
			if (domain.length() < 1)
				domain = null;

			savelw.setSetting(host, port, domain);
			this.setVisible(false);
		}
	}

}
